package com.atguigu.lease.web.admin.controller.apartment;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.module.entity.FacilityInfo;
import com.atguigu.lease.module.enums.ItemType;
import com.atguigu.lease.web.admin.service.FacilityService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/facility")
@Tag(name = "配套信息管理",description = "facilityInfoController")
public class FacilityInfoController {

    @Autowired
    private FacilityService facilityService;

    @GetMapping("list")
    @Operation(summary = "查询配套设备信息")
    public Result<List<FacilityInfo>> getList(@RequestParam ItemType type){
        LambdaQueryWrapper<FacilityInfo>lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(FacilityInfo::getType,type);
        return Result.ok(facilityService.list(lambdaQueryWrapper));
    }

    @PostMapping("saveOrUpdate")
    @Operation(summary = "更新或保存配套信息")
    public Result saveOrUpdate(@RequestBody FacilityInfo facilityInfo){
        facilityService.saveOrUpdate(facilityInfo);
        return Result.ok();
    }

    @DeleteMapping("deleteById")
    @Operation(summary = "删除配套信息")
    public Result delete(@RequestParam Long id){
        facilityService.removeById(id);
        return Result.ok();
    }

}
